package org.minos.edit.controller
{
	import flash.events.Event;
	import org.aswing.CenterLayout;
	import org.aswing.geom.IntDimension;
	import org.aswing.JFrame;
	import org.minos.edit.EditFacate;
	import org.minos.edit.model.AssetsProxy;
	import org.minos.edit.view.components.SelectAssetsPane;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class SelectFileCommand extends SimpleCommand
	{
		
		override public function execute( notification : INotification ) : void
		{
			super.execute( notification );
			
			var typeFilter : Array = [];
			switch ( notification.getType() )
			{
				case AssetsProxy.SOUND: 
					typeFilter = [ ".mp3" ];
					break;
				case AssetsProxy.MOVIE: 
					typeFilter = [ ".swf" , ".mp4" , ".flv" ];
					break;
				case AssetsProxy.SWF: 
					typeFilter = [ ".swf" ];
					break;
				default: 
					typeFilter = [ ".swf" , ".mp4" , ".flv" , ".mp3" ]; //all
			}
			
			var dialog : JFrame = new JFrame( null , "资源列表" , true );
			var pane : SelectAssetsPane = new SelectAssetsPane( AssetsProxy( facade.retrieveProxy( AssetsProxy.NAME ) ).getData() as Array , typeFilter , [ "文件" , "相对路径" , "备注" ] , [ "label" , "url" , "des" ] );
			pane.setPreferredSize( new IntDimension( 600 , 400 ) );
			dialog.setContentPane( pane );
			
			pane.getOkButton().addActionListener( onOk );
			pane.getCancelButton().addActionListener( onCancel );
			
			//dialog
			dialog.pack();
			dialog.show();
			sendNotification( EditFacate.POSITION , dialog );
			
		// ----- event medhots ----- //
			
			function onOk( e : Event ) : void
			{
				if ( notification.getBody() && notification.getBody().tf )
				{
					notification.getBody().tf.setText( pane.getSelectedVO() ? pane.getSelectedVO().url : "" );
					notification.getBody().tf.updateUI();
				}
				dialog.dispose();
			}
			
			function onCancel( e : Event ) : void
			{
				dialog.dispose();
			}
			
		}
	
	}

}